## Universidade Federal do Rio Grande do Sul - Instituto de Informatica
## Departamento de Informatica Teorica
## Modelos de Linguagem de Programacao - 2013/1
## Professor: Lucas Schnorr
## Alunos: Felipe Schimidt e Mario Gasparoni Junior
##
##
## 
## Implementacao do modulo 'background' seguindo recomendacoes em:
## http://www.pygame.org/docs/
import commons, pygame

class Background:
	'Backgrounds Class of the game.'

	###ATTRIBUTES/CONSTANTS###

	backgroundImagePath = 'images/background.png'
	background = 0
    
	#Floor    
	default_floor = pygame.image.load("images/default_floor_tiles.png")

	#Player
	PLAYER_X_POS = 500
	PLAYER_Y_POS = 40
	player = pygame.image.load("images/player.png")

	#Barrel
	BARREL_X_POS = 600
	BARREL_Y_POS = 220
	barrel = pygame.image.load("images/barrel.png")

	talk_delay = 40 #talk delay eh usada no metodo animate, mas nao entendi bem ainda como funciona esse atributo e o metodo animated()

	#Others atributes/constants
	COLLOR_YELLOW=(255,255,0)

	
	###METHODS###

	def createBackgroundImage(self,screen):
		 #Background image    
		self.background = pygame.image.load("images/background.png")
		#the background image is lagging the game!
		screen.blit(self.background, [0, 0])

	def createFloorImage(self, screen):	
		pos_y = 200
		pos_x = 0
		for i in xrange(4):
			pos_x = 0
			while pos_x < commons.MAX_HEIGHT:
				screen.blit(self.default_floor, [pos_x, pos_y])
				pos_x += 20
			pos_y += 20

	def createBarrel(self,screen):
		screen.blit(self.barrel, [self.BARREL_X_POS, self.BARREL_Y_POS])
		screen.blit(self.player, [self.PLAYER_X_POS, self.PLAYER_Y_POS])

	def animate(self, screen):
		if self.talk_delay <= 0:
			myfont = pygame.font.SysFont("monospace", 15)
			label = myfont.render("Caixa 1", 1, COLOR_YELLOW)
			screen.blit(label, (40, 5))
			self.talk_delay = 40

	def create(self, screen):
		self.createBackgroundImage(screen)
		self.createFloorImage(screen)
		self.createBarrel(screen)
		self.animate(screen)

	def game_over(self, screen):
		myfont = pygame.font.SysFont("monospace", 50)
		label = myfont.render("GAME OVER!", 1, (255,255,0))
		screen.blit(label, (170, 200))
